services:
  shard1:
    image: spqr-shard-image
    environment:
      - POSTGRES_USER=regress
      - POSTGRES_DB=regress
    ports:
      - "5500:6432"
    hostname: spqr_shard_1
    container_name: spqr_shard_1
    healthcheck:
      test: psql -h spqr_shard_1 -p 6432 -U regress -d regress
      interval: 10s
      timeout: 3s
      retries: 50
  shard2:
    image: spqr-shard-image
    environment:
      - POSTGRES_USER=regress
      - POSTGRES_DB=regress
    ports:
      - "5501:6432"
    hostname: spqr_shard_2
    container_name: spqr_shard_2
    healthcheck:
      test: psql -h spqr_shard_2 -p 6432 -U regress -d regress
      interval: 10s
      timeout: 3s
      retries: 50
  router:
    build:
      dockerfile: ./docker/router/Dockerfile
      context: ../../
    ports:
      - "6432:6432"
      - "7432:7432"
      - "7012:7002"
    environment:
      - ROUTER_CONFIG=${ROUTER_CONFIG}
      - ROUTER_LOG='router1.log'
      - 'ROUTER_HOST=host: ''regress_router'''
      - COORDINATOR_CONFIG=${COORDINATOR_CONFIG}
    hostname: regress_router
    container_name: regress_router
    depends_on:
      shard1:
        condition: service_healthy
      shard2:
        condition: service_healthy
      kdc:
        condition: service_started
    healthcheck:
      test: psql -h regress_router -p 6432 -U regress -d regress
      interval: 10s
      timeout: 3s
      retries: 50
    volumes:
      - keytab:/keytab
      - ./conf/kdc/krb5.conf:/etc/krb5.conf
  router2:
    build:
      dockerfile: ./docker/router/Dockerfile
      context: ../../
    ports:
      - "6433:6432"
      - "7433:7432"
      - "7022:7002"
    environment:
      - ROUTER_CONFIG=${ROUTER_CONFIG}
      - ROUTER_LOG='router2.log'
      - 'ROUTER_HOST=host: ''regress_router_2'''
      - COORDINATOR_CONFIG=${COORDINATOR_CONFIG_2}
    hostname: regress_router_2
    container_name: regress_router_2
    depends_on:
      shard1:
        condition: service_healthy
      shard2:
        condition: service_healthy
    healthcheck:
      test: psql -h regress_router_2 -p 6432 -U regress -d regress
      interval: 10s
      timeout: 3s
      retries: 50
    volumes:
      - keytab:/keytab
      - ./conf/kdc/krb5.conf:/etc/krb5.conf
  coordinator:
    build:
      dockerfile: ./docker/coordinator/Dockerfile
      context: ../../
    ports:
      - "7002:7002"
      - "7003:7003"
    environment:
      - COORDINATOR_CONFIG=/spqr/test/feature/conf/coordinator.yaml
    hostname: regress_coordinator
    container_name: regress_coordinator
    depends_on:
      - "router"
      - "router2"
      - "qdb01"

  coordinator2:
    build:
      dockerfile: ./docker/coordinator/Dockerfile
      context: ../../
    ports:
      - "7032:7002"
      - "7033:7003"
    environment:
      - COORDINATOR_CONFIG=/spqr/test/feature/conf/coordinator2.yaml
    hostname: regress_coordinator_2
    container_name: regress_coordinator_2
    depends_on:
      - "router"
      - "router2"
      - "qdb01"

  qdb01:
    image: 'bitnami/etcd:latest'
    hostname: regress_qdb_0_1
    container_name: regress_qdb_0_1
    environment:
      ALLOW_NONE_AUTHENTICATION: "yes"
      ETCD_LOG_LEVEL: "debug"
    ports:
      - "2379:2379"

  ldapserver:
    image: "bitnami/openldap:latest"
    hostname: regress_ldap_server
    container_name: regress_ldap_server
    environment:
      - LDAP_ROOT=dc=example,dc=com
      - LDAP_ADMIN_USERNAME=admin
      - LDAP_ADMIN_PASSWORD=adminpassword
      - LDAP_USERS=regress
      - LDAP_PASSWORDS=12345678
      - LDAP_PORT_NUMBER=389
      - LDAP_LDAPS_PORT_NUMBER=636
    ports:
      - "1389:389"
      - "1636:636"
    healthcheck:
      test: ldapwhoami -D "cn=regress,ou=users,dc=example,dc=com" -w 12345678
      interval: 10s
      timeout: 3s
      retries: 50

  ldapserver2:
    image: "bitnami/openldap:latest"
    hostname: regress_ldap_server_2
    container_name: regress_ldap_server_2
    environment:
      - LDAP_ROOT=dc=example,dc=com
      - LDAP_ADMIN_USERNAME=admin
      - LDAP_ADMIN_PASSWORD=adminpassword
      - LDAP_USERS=regress
      - LDAP_PASSWORDS=12345678
      - LDAP_PORT_NUMBER=389
      - LDAP_LDAPS_PORT_NUMBER=636
    ports:
      - "2389:389"
      - "2636:636"
    healthcheck:
      test: ldapwhoami -D "cn=regress,ou=users,dc=example,dc=com" -w 12345678
      interval: 10s
      timeout: 3s
      retries: 50

  kdc:
    build:
      context: ./conf/kdc
    volumes:
      - ./conf/kdc/start.sh:/start.sh
      - keytab:/keytab
volumes:
  keytab:
#networks:
#  mysync_net:
#    driver: bridge
#    ipam:
#      driver: default
#      config:
#       - subnet: 192.168.233.0/24
#         gateway: 192.168.233.1
